<?php
include_once "settings.php";



function moveFile($srcFileName,$targetFileName,$IMPORT_LOG_FILE)
{
	// error/warnings/notices OFF (folder already exists)
	error_reporting(0);
	$era=error_get_last();
	print2log($IMPORT_LOG_FILE, implode(", ", $era));

	mkdir(dirname($targetFileName));

	// error/warnings/notices ON
	error_reporting(-1);

	rename($srcFileName,$targetFileName);
}


$currentDirContent = getFileListFromImportDir($IMPORT_DIR) ;

print2log($IMPORT_LOG_FILE, "Moving files" . PHP_EOL) ;

foreach ($currentDirContent as $currentBookFile)
{
	moveFile($IMPORT_DIR.$currentBookFile, $BOOK_DIR.mb_substr($currentBookFile,0,2)."/".$currentBookFile,$IMPORT_LOG_FILE) ;
	print2log($IMPORT_LOG_FILE, "File ".$IMPORT_DIR.$currentBookFile." moved to: ".$BOOK_DIR.mb_substr($currentBookFile,0,2)."/".$currentBookFile) ;
}



?>